home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRINS.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  111 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strins- Inserts one string within another.
  10. ;
  11. ; inputs:
  12. ;
  13. ;    ES:DI- Points at destination string, the one into which the source
  14. ;           string will be appended.
  15. ;
  16. ;    DX:SI- Points at the string to insert.
  17. ;
  18. ;    CX-    Index into source string (ES:DI) to begin insertion.
  19. ;
  20. ;
  21. ; Note: The destination string's (ES:DI) buffer must be sufficiently large
  22. ;    to hold the result of the concatentation of the two strings.
  23. ;
  24.         public    sl_strins
  25. ;
  26. srcseg        equ    (0-2)[bp]
  27. destseg        equ     (0-4)[bp]
  28. insindx        equ    (0-6)[bp]
  29. source        equ    (0-8)[bp]
  30. dest        equ    (0-10)[bp]
  31. ;
  32. sl_strins    proc    far
  33.         push    bp
  34.         mov    bp, sp
  35.         push    dx
  36.         push    es
  37.         push    cx
  38.         push    si
  39.         push    di
  40.         pushf
  41.         push    ax
  42.         push    bx
  43.         push    ds
  44. ;
  45.         cld
  46. ;
  47. ; Compute the length of the string to insert.
  48. ;
  49.         xchg    si, di
  50.         mov    es, dx            ;(srcseg)
  51.         mov    al, 0
  52.         mov    cx, 0ffffh
  53.     repne    scasb
  54.         neg    cx
  55.         dec    cx
  56.         dec    cx
  57.         mov    bx, cx            ;Save for later.
  58. ;
  59. ; Find the length of the dest string.
  60. ;
  61.         xchg    si, di
  62.         mov    es, destseg
  63.         mov    cx, 0ffffh
  64.     repne    scasb
  65. ;
  66. ; Compute the address of the insertion point:
  67. ;
  68.         mov    dx, dest
  69.         add    dx, insindx
  70.         cmp    dx, di            ;See if beyond end of string.
  71.         jb    InsOkay
  72.         lea    dx, (0-1)[di]
  73. InsOkay:
  74. ;
  75. ; Make room for the insertion.
  76. ;
  77.         mov    ds, destseg
  78.         mov    si, di
  79.         add    si, bx
  80.         xchg    si, di
  81.         mov    cx, bx
  82.         std
  83.     rep    movsb
  84. ;
  85. ; Now perform the insertion.
  86. ;
  87.         cld
  88.         mov    si, source
  89.         mov    di, dx
  90.         mov    cx, bx
  91.         mov    ds, srcseg
  92.     rep    movsb
  93. ;
  94. ;
  95.         pop    ds
  96.         pop    bx
  97.         pop    ax
  98.         popf
  99.         pop    di
  100.         pop    si
  101.         pop    cx
  102.         pop    es
  103.         pop    dx
  104.         pop    bp
  105.         ret
  106. sl_strins    endp
  107. ;
  108. ;
  109. stdlib        ends
  110.         end
  111.